﻿@using EmployeeLeaveSystem.Shared;
@using EmployeeLeaveSystem.Shared.Models;
@using M=EmployeeLeaveSystem.Shared.Models;
@inject IMessageService _MessageService;
@inject HttpClient _HttpClient;
@inject ModalService _modalService;
@inject ModalService _modalService;

<h3>认定加班信息</h3>
<p>在这里审核您需要审核的认定信息，请做出判断</p>
<Table DataSource="listWOMs">
    <PropertyColumn Property="x=>x.Id" />
    <PropertyColumn Property="x=>x.Staff.Name" />
    <PropertyColumn Property="x=>x.StartTime" />
    <PropertyColumn Property="x=>x.EndTime" />
    <PropertyColumn Property="x=>(x.EndTime-x.StartTime).TotalHours" Title="加班时长" />
    <PropertyColumn Property="x=>x.Created" />
    <PropertyColumn Property="x=>x.AcceptTag" />
    <ActionColumn Title="操作">
        <a @onclick="()=>{Update(AddWOMAcceptTag.已通过,context.Id);context.AcceptTag=AddWOMAcceptTag.已通过;}">批准</a>
        <a @onclick="()=>{Update(AddWOMAcceptTag.拒绝,context.Id);context.AcceptTag=AddWOMAcceptTag.拒绝;}">驳回</a>
        <a @onclick="()=>{OpenModal(context.Id);}">查看</a>
    </ActionColumn>
</Table>
@code {
    List<M.AddWOM> listWOMs = new();
    protected override async Task OnInitializedAsync() {
        listWOMs = await _HttpClient.GetFromJsonAsync<List<M.AddWOM>>($"api/OverTime/GetWOMsByManagerUsrId?id={GobalManager.myInfo.Id}");
    }
    void Update(AddWOMAcceptTag acceptFlag, int id) {
        _HttpClient.GetAsync($"api/OverTime/Update?AcceptFlag={acceptFlag}&id={id}");
        _MessageService.Success("更新状态成功");
    }
    private async Task OpenModal(int Id) {
        var modalConfig = new ModalOptions {
                    Title = "详情",
                    Draggable = true,
                    Footer = null,
                    Maximizable = true,
                    Width = "80vw",
                    Content = @<ViewWOMManager Id="Id" />
        };

        await _modalService.CreateModalAsync(modalConfig);
    }
}
